using UnityEngine;

namespace Game.Component
{
	public class ItemComponentTrigger : MonoBehaviour
	{
		public delegate void EnterCollision(BaseItem item, ItemComponentTrigger trigger);

		public delegate void ExitCollision(BaseItem item, ItemComponentTrigger trigger);

		public delegate Transform AttachItem(BaseItem item, ItemComponentTrigger trigger);

		public enum Type
		{
			Default = 0,
			LeftHand = 1,
			RightHand = 2,
			LeftLeg = 3,
			RightLeg = 4,
			Mouth = 5,
			Head = 6,
			Face = 7,
			Body = 8,
			LeftTyre = 9,
			RightTyre = 10,
			CarColor = 11,
			WaterOutlet = 12,
			ElectricMachineBox = 13,
			InfusionBagBox = 14
		}

		public Type type;

		public BaseItem owner;

		public EnterCollision OnEnterCollision;

		public ExitCollision OnExitCollision;

		public AttachItem OnAttachItem;

		private void OnTriggerEnter2D(Collider2D collision)
		{
			if (collision.gameObject.layer == 9 && (type == Type.LeftLeg || type == Type.RightLeg))
			{
				BaseItem component = collision.transform.parent.GetComponent<BaseItem>();
				if (component != null && OnEnterCollision != null)
				{
					OnEnterCollision(component, this);
				}
			}
		}

		private void OnTriggerExit2D(Collider2D collision)
		{
			if (collision.gameObject.layer == 9 && (type == Type.LeftLeg || type == Type.RightLeg))
			{
				BaseItem component = collision.transform.parent.GetComponent<BaseItem>();
				if (component != null && OnExitCollision != null)
				{
					OnExitCollision(component, this);
				}
			}
		}

		public void Init(BaseItem owner, Type componentType, EnterCollision onEnterColl, ExitCollision onExitColl, AttachItem onAttachItem)
		{
			this.owner = owner;
			type = componentType;
			OnEnterCollision = onEnterColl;
			OnExitCollision = onExitColl;
			OnAttachItem = onAttachItem;
		}
	}
}
